- /* sloplus.cpp by K.Tsuru */
- // function ID = 201 DARDIX, BRADIX
- /**********************
- SLong class
- operator+() return m+n
- ***********************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- static const char* func = "SL +";
- SLong operator+(const SLong& m, const SLong& n) {
- if( m.Type() != n.Type() ) m.SetError(m.RADIX_ERR, func, 201);
- int s = m.Sign(201) * n.Sign(201);
-
- if( !s ){ //One of m and n is zero.
- if( m.Sign() == 0 ) return n;
- else return m;
- } else if ( s > 0 ){ //same sign
- SLong t;
- //It lets m >= n. See DDMult().
- if( m.aHead < n.aHead ) return LLAdd(n, m);
- return LLAdd(m, n); //sign is same as that of m(setted in LLAdd())
- } else { //diffrent sign
- SLong r(m.Type(), 0);
- int c = LLCompare(m, n);
- // m + n = m -(-n) = n-(-m)
- if(c > 0){
- r = n; r.ChangeSign(201); // r = -n
- return LLSub(m, r); // m > n
- }
- if(c){
- r = m; r.ChangeSign(201); // r = -m
- return LLSub(n, r); // m < n
- }
- r.SetZero();
- return r; // c = 0 : m = n
- }
- }
sloplus.cpp : last modifiled at 2015/11/27 14:24:50(1,053 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).